package com.example.caimogu.fragmentAdapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.caimogu.bean.Goods;
import com.example.caimogu.bean.Order;
import com.example.caimogu.businessapp.R;
import com.example.caimogu.fragmentImpl.UnhandledOrderImpl;

import java.util.List;

/**
 * Created by Caimogu on 2016/4/21.
 */
public class UnhandledOrderAdapter extends BaseAdapter {
    private List<Order> orders;
    private LayoutInflater inflater;
    private Context context;

    public UnhandledOrderAdapter(List<Order> orders, LayoutInflater inflater,Context context) {
        this.orders = orders;
        this.inflater = inflater;
        this.context = context;
    }

    @Override
    public int getCount() {
        return orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(position);
    }

    @Override
    public long getItemId(int position) {
        //return goodsList.get(position).getId();
        return 1001;
    }

    @Override
    public View getView( final int position, View convertView, ViewGroup parent) {
        convertView =  inflater.inflate(R.layout.unhandledorder_goodslist,null);

        //ImageView snap = (ImageView) convertView.findViewById(R.id.iv_uo_snap_goods);
        TextView title=(TextView)convertView.findViewById(R.id.tv_uo_goods_name);
        TextView content=(TextView)convertView.findViewById(R.id.tv_uo_goods_info);
        Button btn_accept = (Button) convertView.findViewById(R.id.btn_uo_gl_accept);
        Button btn_deny = (Button) convertView.findViewById(R.id.btn_uo_gl_deny);
        title.setText("订单者："+orders.get(position).getCid());
        content.setText("所定商品号:份数 "+orders.get(position).getGoodsIDs()+"  备注："+orders.get(position).getNote());

        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,orders.get(position).getCid() , Toast.LENGTH_SHORT).show();

            }
        });
       btn_accept.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Log.i("caimogu", "UnhandledOrderAdapter...goodslist...btn_accept");
                Toast.makeText(context, "接收一个订单", Toast.LENGTH_SHORT).show();
                //orders.get(position).setStatus(0);
                UnhandledOrderImpl unhandledOrder = new UnhandledOrderImpl();
                unhandledOrder.changeOrdersStatus(orders.get(position).getOid(),0);
            }
        });
        btn_deny.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Log.i("caimogu","UnhandledOrderAdapter...goodslist...btn_deny");
                Toast.makeText(context, "拒绝了一个订单", Toast.LENGTH_SHORT).show();
                UnhandledOrderImpl unhandledOrder = new UnhandledOrderImpl();
                unhandledOrder.changeOrdersStatus(orders.get(position).getOid(), 2);

            }
        });



        return convertView;
    }
}
